package com.lykj.llw.box.ui.activity

import android.os.Bundle
import com.blankj.utilcode.util.GsonUtils
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.lykj.lib_base.app.BaseApplication
import com.lykj.lib_base.base.BaseActivity
import com.lykj.lib_base.internal.extfun.clickWithTrigger
import com.lykj.lib_base.internal.utils.ToastUtils
import com.lykj.lib_base.net.http.CustomResponseBodyObserver
import com.lykj.lib_base.net.http.RetrofitManager
import com.lykj.llw.box.data.bean.response.ShareInfoResponse
import com.lykj.llw.box.databinding.ActDetailShareBinding
import com.lykj.llw.box.ui.diafrg.ShareDiaFrg
import io.reactivex.disposables.Disposable
import okhttp3.ResponseBody

/**
 * ================================================
 * 游戏分享页面
 * ================================================
 *
 * @author gosha
 * @date 2023/12/1-09:58
 */
class GameShareActivity : BaseActivity() {
    lateinit var binding: ActDetailShareBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActDetailShareBinding.inflate(layoutInflater)
        setContentView(binding.root)

        initUI()
        initData()
        setListener()
    }

    override fun initUI() {
    }

    //获取分享相关信息
    private fun obtainShareInfo() {
        RetrofitManager.instance.obtainShareInfo(object :
            CustomResponseBodyObserver<ResponseBody>() {
            override fun onSubscribe(d: Disposable) {
                addDisposables(this@GameShareActivity, d)
            }

            override fun specificHandle(responseBody: String) {
                val bean = GsonUtils.fromJson(responseBody, ShareInfoResponse::class.java)

                binding.tvEarning.text = "${bean.data?.money}"
                binding.tvNum.text = "${bean.data?.inviteNum}"
            }

            override fun handleException(ret: String, msg: String?) {
                msg?.let {
                    ToastUtils.showShort(this@GameShareActivity, it)
                }
            }
        })
    }

    override fun initData() {
        obtainShareInfo()
    }

    override fun onResume() {
        super.onResume()

        ImmersionBar.with(this)
            .transparentBar()
            .statusBarDarkFont(true) //状态栏字体是深色，不写默认为亮色
            .navigationBarDarkIcon(true)
            .hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR)
            .navigationBarEnable(false)
            .init()
    }

    override fun setListener() {
        binding.ivBack.clickWithTrigger {
            finish()
        }

        binding.tvBtnShare.clickWithTrigger(200) {
            ShareDiaFrg()
                .setShareParam(
                    "盒子",
                    "攒趣盒子是安全专业的手游平台，集精品游戏、福利游戏、BT游戏于一体的精品手机游戏平台",
                    "",
                    "http://hezi-h5.66wsy.com/hezi_register?param=1-${BaseApplication.instance?.getUserInfo()?.channelId}-${BaseApplication.instance?.getUserInfo()?.id}"
                )
                .show(supportFragmentManager, "分享弹窗")
        }
    }

    override fun onDestroy() {
        removeDisposables(this)
        super.onDestroy()
    }
}